<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>滴答办公系统-我的信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="media/layui/css/layui.css" media="all">
    <script type="text/javascript" src="media/js/jquery.min.js"></script>
  </head>
  <body>
    <div class="layui-container" style="margin-top: 5px">
      <form class="layui-form" action="studentadd.do" method="post">
        <div class="layui-form-item">
          <label class="layui-form-label">姓名</label>
          <div class="layui-input-block">
            <div id="name" class="layui-form-mid layui-word-aux">小王</div>
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">密码</label>
          <div class="layui-input-block">
            <div id="pass" class="layui-form-mid layui-word-aux">********</div>
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">头像</label>
          <div class="layui-input-block">
            <div class="layui-form-mid layui-word-aux">
              <img id="photo" src="media/images/logo.png" style="width: 60%;" />
            </div>
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label" style="width: 100px;">上次登录时间</label>
          <div class="layui-input-inline">
            <div id="time" class="layui-form-mid layui-word-aux">2010-10-01 23:23:23</div>
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">状态</label>
          <div class="layui-input-inline">
            <div id="flag" class="layui-form-mid layui-word-aux">启用</div>
          </div>
        </div>
      </form>
    </div>


    <script src="media/layui/layui.js"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
    <script>
      var form;
      layui.use(
        ['form', 'upload', 'layedit', 'laydate'],
        function() {
          form = layui.form, layer = layui.layer, layedit = layui.layedit, laydate = layui.laydate;
          var upload = layui.upload;
          //日期
          laydate.render({
            elem: '#date1'
          });
          laydate.render({
            elem: '#date2'
          });
        });
        
        function getQueryVariable(variable) {
          var query = window.location.search.substring(1);
          var vars = query.split("&");
          for (var i = 0; i < vars.length; i++) {
            var pair = vars[i].split("=");
            if (pair[0] == variable) {
              return pair[1];
            }
          }
          return (false);
        }
        
        function init() {
          $.ajax({
            url: "/emp/emp/getEmp",
            type: "POST",
            dataType: "json",
            data: {
              "id": getQueryVariable("id")
            },
            success: function(data) {
              analyseData(data);
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
              alert(XMLHttpRequest.status);
              alert(XMLHttpRequest.readyState);
              alert(textStatus);
            }
          });
        }
        
        init();
        
        function analyseData(data) {
          var no = data.emp.no;
          var name = data.emp.name;
          var passLength = data.emp.passLength;
          var photo = data.emp.photo;
          var flag = data.emp.flag;
          
          $("#name").text(name);
          
          var passStr = "";
          for(var i = 0; i < passLength; i++) {
            passStr += "*";
          }
          $("#pass").text(passStr);
          
          var imgSrc = "/emp/upload/userHeadPhoto/" + photo;
          $("#photo").attr('src', imgSrc);
          
          if(flag == 1) {
            $("#flag").text('启用');
          }else{
            $("#flag").text('禁用');
          }
          
          $.ajax({
            url: "/emp/loginlog/getLoginlogByNo",
            type: "POST",
            dataType: "json",
            data: {
              "no": no
            },
            success: function(data) {
              var time = data.loginlogsList[0].createtime;
              $("#time").text(time);
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
              alert(XMLHttpRequest.status);
              alert(XMLHttpRequest.readyState);
              alert(textStatus);
            }
          });
        }
        
    </script>
  </body>
</html>
